var BSTMG = BSTMG || {};
BSTMG.companyManager = {
	init: function(){
		var that = this;
		//分页功能
		that.selectCompanyList();
	},
	selectCompanyList: function(){
		BSTMG.common.hjhPages("/userAdmin/companyList/search",function(data){
			var companyList = data.companyList;
			var countArr = data.countArr.split('|');
			var $tbody = $("#companyList tbody");
			var $tr = '';
			if(companyList.length > 0) {
				for(var i=0;i<companyList.length;i++){
					var companyInfo = companyList[i];
					var loginNum = setLoginNum(companyInfo);
					var accountMoney = setAccountMoney(companyInfo);
					$tr += '<tr class="odd">';
					$tr += '<td>'+(i+1)+'</td>';
					$tr += '<td>'+checkNull(loginNum)+'</td>';
					$tr += '<td>'+checkNull(companyInfo.phone)+'</td>';
					$tr += '<td>'+parseFloat(accountMoney).toFixed(2)+'元</td>';
					$tr += '<td>'+checkNull(companyInfo.belongCompanyName)+'</td>';
					$tr += '<td>'+checkNull(companyInfo.companyDomainName)+'</td>';
					$tr += '<td>'+countArr[i]+'</td>';
					$tr += '<td>'+checkNull(companyInfo.provinceCodeName) + checkNull(companyInfo.cityCodeName) + checkNull(companyInfo.areaCodeName) + checkNull(companyInfo.address)+'</td>';
					$tr += '<td><a class="btn btn-primary" href="/userAdmin/companyDetail/'+companyInfo.userId+'">查看详情</a>';
					$tr += '<a class="btn btn-danger" href="/userAdmin/companyEmpList/'+companyInfo.userId+'">员工清单</a>';
					$tr += '</td></tr>';
				}
				$tbody.html($tr);
			}else {
				var $tr = '<tr class="odd"><td colspan="7">暂无数据！</td></tr>';
				$tbody.html($tr);
				alert("查询失败！")
			}
		});
	}
}

$(function(){
	BSTMG.companyManager.init();
});

//检测非空
function checkNull(para){
	if(para == null){
		return "";
	}else{
		return para;
	}
}

//设置登陆账号
function setLoginNum(companyInfo){
	if(companyInfo.userEmail != "" && companyInfo.userEmail != null){
		return companyInfo.userEmail;
	}else if(companyInfo.userTel != "" && companyInfo.userTel != null){
		return companyInfo.userTel;
	}else{
		return "";
	}
}

function setAccountMoney(companyInfo){
	if(companyInfo.accountMoney != "" && companyInfo.accountMoney != null){
		return companyInfo.accountMoney;
	}else{
		return 0.00;
	}
}






